<?php
/**
 * 功 能：用户登录检测
 * @authors zhanghong (zhangh@zpdchina.com)
 * @date    2017-03-06
 * @version $Id$
 */
class UpdatemsgstateController extends Yaf_Controller_Abstract
{

    function IndexAction()
    {
        $request = $this->getRequest();
        $user_number = $request->getPost("user_number","");
        $data = $request->getPost("data", "");

        if(empty($user_number)) // 如果登录帐号为空
        {
            Utility::apiJsonError(20002, '请输入正确的登陆账号!');
        }
        
        $yiyuan_id = $request->getPost("yiyuan_id", '');
        if($yiyuan_id === "" )
        {
        	Utility::apiJsonError(20028, '请输入医院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
        	Utility::apiJsonError(20027, '医院ID必须是整型');
        }
        $compression_http_data = $request->getPost("compression_http_data", 'off');
        $data = $this->getRequest()->getPost("data", null);
        if(empty($data)){
        	Utility::apiJsonError('51001','缺少数据');
        }
        $data = Utility::uncompress($data, $compression_http_data);
        $upload_data = json_decode($data, true);

        $msg_id_arr = array_column($upload_data, 'msg_id');
        //print_r($msg_id_arr);exit;
        $statr = array();
        $sql = DB::update('pushmsg_log')
        	->set(['receive_time' => time(), 'state' => 2])
        	->where('msg_id', 'in', $msg_id_arr)
        	->where('user_number', 'like', $user_number."%");

        $is_exists	= $sql->execute();
        if (!$msg_id_arr || !$is_exists) {
        	Utility::apiJsonError('51051','请传有效的参数msg_id');
        }
        $statr = array('state' => $is_exists ? '1' : '0');
        $statr['msg'] = "";
        $statr['error'] = "200";
        $async_result_json = json_encode($statr);
        
        //压缩数据
        $async_result_json = Utility::compress($async_result_json,$compression_http_data);
        echo $async_result_json;
    }

   
}